package edu.xlh.travel.dao;

import edu.xlh.travel.pojo.Scenic;
import edu.xlh.travel.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;

public interface ScenicDao extends JpaRepository<Scenic,String>, JpaSpecificationExecutor<Scenic> {
    @Modifying
    @Query(value = "update t_scenic set " +
            "name = CASE WHEN :#{#scenic.name} IS NULL THEN name ELSE :#{#scenic.name} END," +
            "price = CASE WHEN :#{#scenic.price} IS NULL THEN price ELSE :#{#scenic.price}  END," +
            "comment= CASE WHEN  :#{#scenic.comment} IS NULL THEN comment ELSE :#{#scenic.comment} END, " +
            "start= CASE WHEN  :#{#scenic.start} IS NULL THEN start ELSE :#{#scenic.start} END, " +
            "contry= CASE WHEN  :#{#scenic.contry} IS NULL THEN contry ELSE :#{#scenic.contry} END, " +
            "stock= CASE WHEN  :#{#scenic.stock} IS NULL THEN stock ELSE :#{#scenic.stock} END, " +
            "miaoshu= CASE WHEN  :#{#scenic.miaoshu} IS NULL THEN miaoshu ELSE :#{#scenic.miaoshu} END, " +
            "start_date= CASE WHEN  :#{#scenic.startDate} IS NULL THEN start_date ELSE :#{#scenic.startDate} END " +
            "where id =:#{#scenic.id}",nativeQuery = true )
    void updateScenicByScenicId(@Param("scenic")Scenic scenic);

    @Modifying
    @Query(value = "update t_scenic set " +
            "comment= CASE WHEN  :#{#scenic.comment} IS NULL THEN comment ELSE :#{#scenic.comment} END, " +
            "miaoshu= CASE WHEN  :#{#scenic.miaoshu} IS NULL THEN miaoshu ELSE :#{#scenic.miaoshu} END " +
            "where id =:#{#scenic.id}",nativeQuery = true )
    void editMiaoShuOrComment(@Param("scenic")Scenic scenic);

    @Transactional
    @Modifying
    @Query(value = "update Scenic set delFlag =?2 where id =?1")
    void updateScenicDelFlagByScenicId(String scenicId , String delFlag);
}
